package global

import (
	publisher2 "longmen/server/internal/services/consumers/publisher"
	_const "longmen/server/pkg/common/helper/const"
	"longmen/server/pkg/common/lib/rabbitmq"
)

var (
	PublisherStatistic      *publisher2.PublishStatisticServices
	PublisherTxChat         *publisher2.PublishTxChatServices
	PublisherAnonymousLogin *publisher2.PublishAnonymousServices
	PublisherHistory        *publisher2.PublishHistoryServices
	PublisherAccount        *publisher2.PublishAccountServices
	PublisherActivity       *publisher2.PublishActivityServices
	PublishChannelStats     *publisher2.PublishChannelStatsServices
	PublishPvtChat          *publisher2.PublishPvtChatServices
	PublishFansGroup        *publisher2.PublishFansGroupServices
	rabbitConf              rabbitmq.Config
)

func initConsumerConfig() {
	rabbitConf = rabbitmq.Config{
		Host:     Config.GetString("rabbitmq.host"),
		Port:     Config.GetInt("rabbitmq.port"),
		Username: Config.GetString("rabbitmq.username"),
		Password: Config.GetString("rabbitmq.password"),
		Vhost:    Config.GetString("rabbitmq.vhost"),
	}
}
func InitPublisher() {
	initConsumerConfig()
	var err error
	PublisherStatistic, err = publisher2.NewStatisticPublish(Config, rabbitConf, _const.PusherStatistic, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublisherTxChat, err = publisher2.NewTxChatPublish(Config, rabbitConf, _const.PusherTxChat, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublisherAccount, err = publisher2.NewAccountPublish(Config, rabbitConf, _const.PusherAccount, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublisherActivity, err = publisher2.NewActivityPublish(Config, rabbitConf, _const.PusherActivity, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublishChannelStats, err = publisher2.NewChannelStatsPublish(Config, rabbitConf, _const.PusherChanStats, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublisherAnonymousLogin, err = publisher2.NewAnonymousPublish(Config, rabbitConf, _const.PusherAnonymousLogin, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublisherHistory, err = publisher2.NewHistoryEsPublish(Config, rabbitConf, _const.PusherHistoryEs, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublishPvtChat, err = publisher2.NewPvtChatPublish(Config, rabbitConf, _const.PusherTxPvtChat, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

	PublishFansGroup, err = publisher2.NewTxFansGroupPublish(Config, rabbitConf, _const.PusherTxFansGroup, Log)
	if err != nil {
		Log.Fatalf("Init RabbitPublish Err %v", err)
	}

}
